package com.charging.system.controller;

import java.math.RoundingMode;
import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSONObject;
import com.charging.common.constant.Constants;
import com.charging.common.utils.DateUtils;
import com.charging.system.domain.KxEquip;
import com.charging.system.domain.KxEquipScheme;
import com.charging.system.service.IKxEquipSchemeService;
import com.charging.system.service.IKxEquipService;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.charging.common.annotation.Log;
import com.charging.common.core.controller.BaseController;
import com.charging.common.core.domain.AjaxResult;
import com.charging.common.enums.BusinessType;
import com.charging.system.domain.KxChargingRecord;
import com.charging.system.service.IKxChargingRecordService;
import com.charging.common.utils.poi.ExcelUtil;
import com.charging.common.core.page.TableDataInfo;

/**
 * 充电记录Controller
 *
 * @author charging
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/system/record")
public class KxChargingRecordController extends BaseController
{
    @Resource
    private IKxChargingRecordService kxChargingRecordService;
    @Resource
    private IKxEquipService kxEquipService;
    @Resource
    private IKxEquipSchemeService kxEquipSchemeService;

    /**
     * 查询充电记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(KxChargingRecord kxChargingRecord)
    {
        startPage();
        List<KxChargingRecord> list = kxChargingRecordService.selectKxChargingRecordList(kxChargingRecord);
        return getDataTable(list);
    }
    /**
     * 查询充电记录列表
     */
    @GetMapping("/u_list")
    public TableDataInfo u_list(KxChargingRecord kxChargingRecord)
    {
        startPage();
        List<KxChargingRecord> list = kxChargingRecordService.selectKxChargingRecordList(kxChargingRecord);
        return getDataTable(list);
    }

    /**
     * 导出充电记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:record:export')")
    @Log(title = "充电记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, KxChargingRecord kxChargingRecord)
    {
        List<KxChargingRecord> list = kxChargingRecordService.selectKxChargingRecordList(kxChargingRecord);
        ExcelUtil<KxChargingRecord> util = new ExcelUtil<KxChargingRecord>(KxChargingRecord.class);
        util.exportExcel(response, list, "充电记录数据");
    }

    /**
     * 获取充电记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:record:query')")
    @GetMapping(value = "/{chargingRecordId}")
    public AjaxResult getInfo(@PathVariable("chargingRecordId") Long chargingRecordId)
    {
        return success(kxChargingRecordService.selectKxChargingRecordByChargingRecordId(chargingRecordId));
    }

    /**
     * 新增充电记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:add')")
    @Log(title = "充电记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody KxChargingRecord kxChargingRecord)
    {
        return toAjax(kxChargingRecordService.insertKxChargingRecord(kxChargingRecord));
    }

    /**
     * 修改充电记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "充电记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody KxChargingRecord kxChargingRecord)
    {
        return toAjax(kxChargingRecordService.updateKxChargingRecord(kxChargingRecord));
    }

    /**
     * 删除充电记录
     */
    @PreAuthorize("@ss.hasPermi('system:record:remove')")
    @Log(title = "充电记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chargingRecordIds}")
    public AjaxResult remove(@PathVariable Long[] chargingRecordIds)
    {
        return toAjax(kxChargingRecordService.deleteKxChargingRecordByChargingRecordIds(chargingRecordIds));
    }
}
